package lc.oa.ui;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import lc.oa.R;
import lc.oa.ui.base.MyAppCompatActivity;
import lc.oa.ui.fragment.AchievementFragment;
import lc.oa.ui.fragment.MyFragment;
import lc.oa.ui.fragment.HomeFragment;
import lc.oa.ui.fragment.CalendarFragment;
import lc.oa.ui.fragment.TestFragment;
import lc.oa.ui.listeners.IBottomBarClickListener;
import lc.oa.ui.listeners.OnScanAndVoiceListener;

/**
  *
  * @Description:     主框架页面
  * @Author:         lucifer
  * @CreateDate:     2020/8/7 16:15
  * @UpdateUser:
  * @UpdateDate:
  * @UpdateRemark:
  * @Version:        1.0
 */
public class MainActivity extends MyAppCompatActivity implements IBottomBarClickListener, OnScanAndVoiceListener {

    private FragmentManager fragmentManager;
    private HomeFragment homeFragment=new HomeFragment();
//    @Inject
//    Users users;

    @SuppressLint("LongLogTag")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        init();
        // Log.e("------>注入的users对象为--------->", users.toString());
        homeFragment.setSetBtnClick(new HomeFragment.SetBtnClick() {
            @Override
            public void onClick(View view) {
                Log.e("",""+view);
                Toast.makeText(MainActivity.this, "请假", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void init() {
        fragmentManager = getSupportFragmentManager();
        BottomBar bottomBar = (BottomBar) findViewById(R.id.bottom_bar);
        bottomBar.setIBottomBarClickListener(this);
        bottomBar.findViewById(R.id.frag_main_ll).performClick();
    }

    @Override
    public void onItemClick(int action) {
        Log.e("", "action--->" + action);
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        switch (action) {
            case R.id.frag_calendar_ll:
                fragmentTransaction.replace(R.id.top_bar, new CalendarFragment());
                break;
            case R.id.frag_main_ll:
                fragmentTransaction.replace(R.id.top_bar, new HomeFragment());
                break;
            case R.id.frag_mine_ll:
                fragmentTransaction.replace(R.id.top_bar, new MyFragment());
               // fragmentTransaction.replace(R.id.top_bar, new TestFragment());
                break;
            case R.id.frag_achievement_ll:
                //fragmentTransaction.replace(R.id.top_bar, new AchievementFragment());
                fragmentTransaction.replace(R.id.top_bar, new TestFragment());
                break;
        }
        fragmentTransaction.commit();
    }

    @Override
    public void startScanner() {

    }

    @Override
    public void startSpeak() {

    }
}